package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wmLoginDto.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    //上传

    @PostMapping( "/upload_picture")
    public ResponseResult uploadPic(MultipartFile multipartFile) throws IOException {
        return wmMaterialService.uploadPic(multipartFile);
    }



    //分页查询
    @PostMapping( "/list")
    public ResponseResult list(@RequestBody WmMaterialDto dto) {
        return wmMaterialService.list(dto);
    }

    //删除
    @GetMapping("/del_picture/{id}")
    public ResponseResult delete(@PathVariable Integer id){
        return wmMaterialService.deleteById(id);
    }
    //素材收藏
    @GetMapping("collect/{id}")
    public ResponseResult updateCollection(@PathVariable Integer id){
        return wmMaterialService.update(id);
    }
    //取消收藏
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult upCollection(@PathVariable Integer id){
        return wmMaterialService.update(id);
    }


}
